package com.peanut.baby.comm;

import android.content.Context;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.peanut.baby.R;
import com.peanut.baby.mvp.ask.AskActivity;
import com.peanut.baby.mvp.bbs.list.BBSListActivity;
import com.peanut.baby.mvp.bbs.publish.BBSPublishActivity;
import com.peanut.baby.mvp.calendar.CalendarActivity;
import com.peanut.baby.mvp.livedetail.LiveListActivity;
import com.peanut.baby.mvp.main.MainActivity;
import com.peanut.baby.mvp.qadetail.QAListActivity;
import com.peanut.baby.mvp.trend.list.TrendListActivity;
import com.peanut.baby.mvp.trend.publish.TrendPublishActivity;

import java.util.ArrayList;
import java.util.List;


public class SmallPagerAdapter extends PagerAdapter {

	List<View> views;
	Context context;
	public SmallPagerAdapter( Context context) {
		this.views = getViews(context);
	}

	@Override
	public void destroyItem(View arg0, int arg1, Object arg2) {
		try {
			ViewPager viewPager = (ViewPager) arg0;
			View v = (View) arg2;
			viewPager.removeView(v);
		} catch (Exception e) {
			
		}
	}
	
	@Override
	public int getItemPosition(Object object) {
		return PagerAdapter.POSITION_NONE;
	}

	@Override
	public void finishUpdate(View v) {

	}

	@Override
	public int getCount() {
		return views.size();
	}

	@Override
	public Object instantiateItem(View container, int position) {
		((ViewPager) container).addView(views.get(position), 0);
		return views.get(position);
	}

	@Override
	public boolean isViewFromObject(View v, Object obj) {
		return v == obj;
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {

	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {
	}

	List<View> getViews(Context context){
		List<View> views = new ArrayList<>();
		LayoutInflater inflater = LayoutInflater.from(context);
		View parent1 = inflater.inflate(R.layout.layout_navibar_small_icon,null);
		((ImageView) parent1.findViewById(R.id.navibar_icon)).setImageResource(R.drawable.icon_main_menu_record);
		View parent2 = inflater.inflate(R.layout.layout_navibar_small_icon,null);
		((ImageView) parent2.findViewById(R.id.navibar_icon)).setImageResource(R.drawable.icon_main_menu_ask);
		View parent3 = inflater.inflate(R.layout.layout_navibar_small_icon,null);
		((ImageView) parent3.findViewById(R.id.navibar_icon)).setImageResource(R.drawable.icon_main_menu_bbs);
		View parent4 = inflater.inflate(R.layout.layout_navibar_small_icon,null);
		((ImageView) parent4.findViewById(R.id.navibar_icon)).setImageResource(R.drawable.icon_article);

		views.add(parent1);
		views.add(parent2);
		views.add(parent3);
		views.add(parent4);
		parent1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				CalendarActivity.start(context);
			}
		});
		parent2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				AskActivity.start(context);
			}
		});
		parent3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				TrendPublishActivity.start(context);
			}
		});
		parent4.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				BBSPublishActivity.start(context);
			}
		});

		return views;
	}

}
